import Http from '../../utils/http.js';
let app = getApp()
Component({
  properties: {
    orderInfo:{
      type:Object,
      value:{}
    }
  },
  options: {
    multipleSlots: true
  },
  data: {

  }, // 私有数据，可用于模版渲染
  methods:{
    handleCancel(e){
      const _that = this;
      const orderCode = e.currentTarget.dataset.code;
      const operate = e.currentTarget.dataset.operate;//操作类型（取消/退款）
      const type = e.currentTarget.dataset.type;//商品类型
      if (operate === 'qx'){//取消
        wx.showModal({
          title: '提示',
          content: '订单还未付款，确定要取消吗？',
          success(res) {
            if (res.confirm) {
              _that.cancelReq(orderCode, operate)
            } else if (res.cancel) {

            }
          }
        })
      } else {//退款
        if (type === 'ROOM_COMMODITY'){//酒店商品
          wx.showModal({
            title: '提示',
            content: ' 亲，酒店类商品，大于三天，退全款，一天到三天内，退50%，当天不退，如遇特殊情况，请拨打客服电话 15368989421',
            success(res) {
              if (res.confirm) {
                _that.cancelReq(orderCode, operate)
              } else if (res.cancel) {

              }
            }
          })
        }else{
          wx.showModal({
            title: '提示',
            content: '订单已支付，确定要申请退款吗？',
            success(res) {
              if (res.confirm) {
                _that.cancelReq(orderCode, operate)
              } else if (res.cancel) {

              }
            }
          })
        }
      }
    },
    cancelReq(orderCode, operate){
      Http.Request('PUT', `/api/customer/order/cancel/${orderCode}/v1`).then(res => {
        console.log(res)
        wx.showToast({
          title: operate==='qx'?'订单取消成功':'申请退款成功',
          icon: "success",
          duration: app.globalData.duration
        })
        setTimeout(() => {
          this.triggerEvent('getOrderList')
        }, app.globalData.duration)
      }).catch(err => {
        wx.showToast({
          title: err,
          icon: "none",
          duration: app.globalData.duration
        })
      })
    },
    gotoEvaluation(e){
      const orderCode = e.currentTarget.dataset.code;
      const type = e.currentTarget.dataset.type;
      const commodityInfo = JSON.stringify(e.currentTarget.dataset.commodityinfo);
      wx.navigateTo({
        url: `../../pages/evaluation/index?orderCode=${orderCode}&commodityInfo=${commodityInfo}&type=${type}`,
      })
    },
    getOrderDetail(e){
      const comtype = e.currentTarget.dataset.comtype;
      const orderCode = e.currentTarget.dataset.code;
      console.log(this.data.orderInfo)
      switch(comtype){
        case 'ROOM_COMMODITY':
          wx.navigateTo({
            url: `../../pages/houseList/houseDetail/createOrder/index?orderCode=${orderCode}`,
          })
          break;
        case 'VIRTUAL_COMMODITY':
          wx.navigateTo({
            url: `../../pages/travelList/travelDetail/createOrder/index?orderCode=${orderCode}`,
          })
          break;
        case 'MATERIAL_COMMODITY':
          wx.navigateTo({
            url: `../../pages/shiwuList/shiwuDetail/createOrder/index?orderCode=${orderCode}`,
          })
          break;
        case 'CAR_COMMODITY':
          wx.navigateTo({
            url: `../../pages/carList/carDetail/createOrder/index?orderCode=${orderCode}`,
          })
          break;
      }
    }
  }

})